home *** CD-ROM | disk | FTP | other *** search
/ Deutsche Edition 1 / Deutsche Edition 1.iso / amok / 051-060 / amok58 / nprint / txt / stringopstest.mod < prev    next >
Text File  |  1993-11-04  |  13KB  |  442 lines

  1. (**********************************************************************
  2.  
  3.     :Program.    StringOpsTest.mod
  4.     :Contents.   Test module for StringOps
  5.     :Author.     Nicolas Benezan [bne]
  6.     :Address.    Postwiesenstr. 2, D7000 Stuttgart 60
  7.     :Phone.      711/333679
  8.     :Copyright.  Public Domain
  9.     :Language.   Modula-2
  10.     :Translator. M2Amiga A+L V3.2d
  11.     :Imports.    StringOps [bne]
  12.     :History.    V1.0a [bne] 17.May.1989
  13.  
  14. **********************************************************************)
  15.  
  16. MODULE StringOpsTest;
  17.  
  18. FROM Arts       IMPORT BreakPoint;
  19. FROM InOut      IMPORT Write, WriteInt, WriteLn, WriteString;
  20. FROM StringOps  IMPORT Append, AppendChar, Assign, CapChar, CapString,
  21.                        Compare, Concat, DeleteSubString, FindChar,
  22.                        FindSubString, InsertChar, InsertSubString, Length,
  23.                        OverWrite, SubString;
  24. FROM SYSTEM     IMPORT ADR;
  25.  
  26. VAR
  27.   s8,t8:ARRAY [0..7] OF CHAR;
  28.   s12,t12:ARRAY [0..11] OF CHAR;
  29.   s6,t6:ARRAY [0..5] OF CHAR;
  30.   s4,t4:ARRAY [0..3] OF CHAR;
  31.   c,d:CHAR;
  32.   n:INTEGER;
  33.  
  34. PROCEDURE Result(Str:ARRAY OF CHAR);
  35.   BEGIN
  36.     WriteString(" = ");
  37.     WriteString(Str);
  38.     WriteLn;
  39.   END Result;
  40.  
  41. PROCEDURE Print(Text:ARRAY OF CHAR);
  42.   BEGIN
  43.     WriteString(Text);
  44.   END Print;
  45.  
  46. PROCEDURE Number(n:INTEGER);
  47.   BEGIN
  48.     WriteString(": ");
  49.     WriteInt(n,1);
  50.     WriteLn;
  51.   END Number;
  52.  
  53. BEGIN
  54. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  55. (* Append                                                               *)
  56. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  57.   BreakPoint(ADR("Testing Append"));
  58.   Print("'text' + 'test' into s8");
  59.   s8:="text";
  60.   Append(s8,"test");
  61.   Result(s8);
  62.   Print("'text' + 'test' into s11");
  63.   s12:="text";
  64.   Append(s12,"test");
  65.   Result(s12);
  66.   Print("'text' + 'test' into s4");
  67.   s4:="text";
  68.   Append(s4,"test");
  69.   Result(s4);
  70.   Print("'text' + 'test' into s6");
  71.   s6:="text";
  72.   Append(s6,"test");
  73.   Result(s6);
  74.   Print("'text' + '' into s8");
  75.   s8:="text";
  76.   Append(s8,"");
  77.   Result(s8);
  78.   Print("'' + 'text' into s8");
  79.   s8:="";
  80.   Append(s8,"text");
  81.   Result(s8);
  82.   WriteLn;
  83.  
  84. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  85. (* AppendChar                                                           *)
  86. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  87.   BreakPoint(ADR("Testing AppendChar"));
  88.   Print("'text' + 'x' into s8");
  89.   s8:="text";
  90.   AppendChar(s8,"x");
  91.   Result(s8);
  92.   Print("'texts' + 'x' into s6");
  93.   s6:="texts";
  94.   AppendChar(s6,"x");
  95.   Result(s6);
  96.   Print("'text' + 'x' into s4");
  97.   s4:="text";
  98.   AppendChar(s4,"x");
  99.   Result(s4);
  100.   Print("'' + 'x' into s8");
  101.   s8:="";
  102.   AppendChar(s8,"x");
  103.   Result(s8);
  104.   WriteLn;
  105.  
  106. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  107. (* Assign                                                               *)
  108. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  109.   BreakPoint(ADR("Testing Assign"));
  110.   Print("'test' s4 to s4");
  111.   s4:="test";
  112.   Assign(s4,t4);
  113.   Result(t4);
  114.   Print("'test' s6 to s4");
  115.   s6:="test";
  116.   Assign(s6,t4);
  117.   Result(t4);
  118.   Print("'test' s4 to s6");
  119.   s4:="test";
  120.   Assign(s4,t6);
  121.   Result(t6);
  122.   Print("'testtext' s8 to s4");
  123.   s8:="testtext";
  124.   Assign(s8,t4);
  125.   Result(t4);
  126.   WriteLn;
  127.  
  128. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  129. (* CapChar                                                              *)
  130. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  131.   BreakPoint(ADR("Testing CapChar"));
  132.   FOR c:=CHR(32) TO CHR(127) DO
  133.     Write(c);
  134.   END;
  135.   WriteLn;
  136.   FOR c:=CHR(32) TO CHR(127) DO
  137.     d:=c;
  138.     CapChar(d);
  139.     Write(d);
  140.   END;
  141.   WriteLn;
  142.   FOR c:=CHR(160) TO CHR(255) DO
  143.     Write(c);
  144.   END;
  145.   WriteLn;
  146.   FOR c:=CHR(160) TO CHR(255) DO
  147.     d:=c;
  148.     CapChar(d);
  149.     Write(d);
  150.   END;
  151.   WriteLn;
  152.   WriteLn;
  153.  
  154. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  155. (* CapString                                                            *)
  156. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  157.   BreakPoint(ADR("Testing CapString"));
  158.   Print("Grüße s6");
  159.   s6:="Grüße";
  160.   CapString(s6);
  161.   Result(s6);
  162.   Print("Grmf s4");
  163.   s4:="Grmf";
  164.   CapString(s4);
  165.   Result(s4);
  166.   WriteLn;
  167.  
  168. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  169. (* FindChar                                                             *)
  170. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  171.   BreakPoint(ADR("Testing FindChar"));
  172.   Print("find 's' in 'teststring' s12");
  173.   s12:="teststring";
  174.   Number(FindChar(s12,"s",0));
  175.   Print("backward");
  176.   Number(FindChar(s12,"s",-9));
  177.   Print("from position 3 (t)");
  178.   Number(FindChar(s12,"s",3));
  179.   Print("backward");
  180.   Number(FindChar(s12,"s",-3));
  181.   Print("from position 4 (s)");
  182.   Number(FindChar(s12,"s",4));
  183.   Print("backward");
  184.   Number(FindChar(s12,"s",-4));
  185.   Print("find 'x' in 'testtext' s8");
  186.   s8:="testtext";
  187.   Number(FindChar(s8,"x",0));
  188.   Print("backward");
  189.   Number(FindChar(s8,"x",-7));
  190.   Print("find 'x' in 'teststring' s12");
  191.   Number(FindChar(s12,"x",0));
  192.   Print("backward");
  193.   Number(FindChar(s12,"x",-9));
  194.   Print("find 'i' in 'testtext' s8");
  195.   Number(FindChar(s8,"i",0));
  196.   Print("backward");
  197.   Number(FindChar(s8,"i",-7));
  198.   Print("find 'x' in '' s4");
  199.   s4:="";
  200.   Number(FindChar(s4,"x",0));
  201.   WriteLn;
  202.  
  203. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  204. (* Compare                                                              *)
  205. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  206.   BreakPoint(ADR("Testing Compare"));
  207.   Print("'test' s4 vs 'test' s4");
  208.   s4:="test";
  209.   t4:="test";
  210.   Number(Compare(s4,t4));
  211.   Print("'test' s8 vs 'test' s8");
  212.   s8:="test";
  213.   t8:="test";
  214.   Number(Compare(s8,t8));
  215.   Print("'test' s4 vs 'test' s8");
  216.   Number(Compare(s4,s8));
  217.   Print("'test' s4 vs 'text' s4");
  218.   s4:="test";
  219.   t4:="text";
  220.   Number(Compare(s4,t4));
  221.   Print("'text' s4 vs 'test' s4");
  222.   Number(Compare(t4,s4));
  223.   Print("'test' s4 vs 'teststring' s12");
  224.   s12:="teststring";
  225.   Number(Compare(s4,s12));
  226.   Print("'test' s4 vs '' s4");
  227.   t4:="";
  228.   Number(Compare(s4,t4));
  229.   WriteLn;
  230.  
  231. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  232. (* DeleteSubString                                                      *)
  233. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  234.   BreakPoint(ADR("Testing DeleteSubString"));
  235.   Print("remove 'test' (0,4) from 'teststring' s12");
  236.   s12:="teststring";
  237.   DeleteSubString(s12,0,4);
  238.   Result(s12);
  239.   Print("remove 'st' (4,2) from 'teststring' s12");
  240.   s12:="teststring";
  241.   DeleteSubString(s12,4,2);
  242.   Result(s12);
  243.   Print("remove 'ing' (7,3) from 'teststring' s12");
  244.   s12:="teststring";
  245.   DeleteSubString(s12,7,3);
  246.   Result(s12);
  247.   Print("deleting whole (0,9) 'teststring' s12");
  248.   s12:="teststring";
  249.   DeleteSubString(s12,0,9);
  250.   Result(s12);
  251.   Print("remove 'test' (0,4) from 'testtext' s8");
  252.   s8:="testtext";
  253.   DeleteSubString(s8,0,4);
  254.   Result(s8);
  255.   Print("remove 't' (4,1) from 'testtext' s8");
  256.   s8:="testtext";
  257.   DeleteSubString(s8,4,1);
  258.   Result(s8);
  259.   Print("remove 'text' (4,4) from 'testtext' s8");
  260.   s8:="testtext";
  261.   DeleteSubString(s8,4,4);
  262.   Result(s8);
  263.   Print("deleting whole (0,8) 'testtext' s8");
  264.   s8:="testtext";
  265.   DeleteSubString(s8,0,8);
  266.   Result(s8);
  267.   Print("deleting over end (4,7) of 'teststring' s12");
  268.   s12:="teststring";
  269.   DeleteSubString(s12,4,7);
  270.   Result(s12);
  271.   Print("deleting over end (4,5) of 'testtext' s8");
  272.   s8:="testtext";
  273.   DeleteSubString(s8,4,5);
  274.   Result(s8);
  275.   Print("deleting nothing (2,0) out of 'teststring' s12");
  276.   s12:="teststring";
  277.   DeleteSubString(s12,2,0);
  278.   Result(s12);
  279.   WriteLn;
  280.  
  281. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  282. (* FindSubString                                                        *)
  283. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  284.   BreakPoint(ADR("Testing FindSubString"));
  285.   Print("find 'str' s4 in 'teststring' s12");
  286.   s4:="str";
  287.   s12:="teststring";
  288.   Number(FindSubString(s12,s4,0));
  289.   Print("from position 3 (t)");
  290.   Number(FindSubString(s12,s4,3));
  291.   Print("from position 4 (s)");
  292.   Number(FindSubString(s12,s4,4));
  293.   Print("from position 5 (s)");
  294.   Number(FindSubString(s12,s4,5));
  295.   Print("find 'ttex' s4 in 'testtext' s8");
  296.   s4:="ttex";
  297.   s8:="testtext";
  298.   Number(FindSubString(s8,s4,0));
  299.   Print("from position 6 (e)");
  300.   Number(FindSubString(s8,s4,6));
  301.   Print("find 'tx' in 'teststring' s12");
  302.   Number(FindSubString(s12,"tx",0));
  303.   Print("find 'in' in 'testtext' s8");
  304.   Number(FindSubString(s8,"in",0));
  305.   Print("find '' in 'test' s4");
  306.   s4:="test";
  307.   Number(FindSubString(s4,"",0));
  308.   Print("find 'xx' in '' s4");
  309.   s4:="";
  310.   Number(FindSubString(s4,"xx",0));
  311.   WriteLn;
  312.  
  313.  
  314. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  315. (* InsertSubString                                                      *)
  316. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  317.   BreakPoint(ADR("Testing InsertSubString"));
  318.   Print("inserting 'test' into 'text' s8 at pos 0");
  319.   s8:="text";
  320.   InsertSubString(s8,"test",0);
  321.   Result(s8);
  322.   Print("inserting 'xx' into 'text' s8 at pos 2");
  323.   s8:="text";
  324.   InsertSubString(s8,"xx",2);
  325.   Result(s8);
  326.   Print("inserting 'test' into 'text' s8 at pos 4");
  327.   s8:="text";
  328.   InsertSubString(s8,"test",4);
  329.   Result(s8);
  330.   Print("inserting 'test' into '' s8 at pos 0");
  331.   s8:="";
  332.   InsertSubString(s8,"test",0);
  333.   Result(s8);
  334.   Print("inserting '' into 'text' s8 at pos 1");
  335.   s8:="text";
  336.   InsertSubString(s8,"",1);
  337.   Result(s8);
  338.   Print("inserting 'test' s4 into 'text' s6 at pos 2");
  339.   s4:="test";
  340.   s6:="text";
  341.   InsertSubString(s6,s4,2);
  342.   Result(s6);
  343.   WriteLn;
  344.  
  345. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  346. (* InsertChar                                                           *)
  347. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  348.   BreakPoint(ADR("Testing InsertChar"));
  349.   Print("inserting 'x' into 'text' s8 at pos 0");
  350.   s8:="text";
  351.   InsertChar(s8,"x",0);
  352.   Result(s8);
  353.   Print("inserting 'y' into 'text' s8 at pos 3");
  354.   s8:="text";
  355.   InsertChar(s8,"y",3);
  356.   Result(s8);
  357.   Print("inserting 'x' into 'text' s8 at pos 4");
  358.   s8:="text";
  359.   InsertChar(s8,"x",4);
  360.   Result(s8);
  361.   Print("inserting 'x' into '' s8 at pos 0");
  362.   s8:="";
  363.   InsertChar(s8,"x",0);
  364.   Result(s8);
  365.   Print("inserting 'x' into 'texttest' s8 at pos 1");
  366.   s8:="texttest";
  367.   InsertChar(s8,"x",1);
  368.   Result(s8);
  369.   Print("inserting 's' into 'text' s4 at pos 2");
  370.   s4:="text";
  371.   InsertChar(s4,"s",2);
  372.   Result(s4);
  373.   WriteLn;
  374.  
  375. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  376. (* Length                                                               *)
  377. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  378.   BreakPoint(ADR("Testing Length"));
  379.   Print("length of 'teststring' s12");
  380.   s12:="teststring";
  381.   Number(Length(s12));
  382.   Print("length of 'testtext' s8");
  383.   s8:="testtext";
  384.   Number(Length(s8));
  385.   Print("length of '' s4");
  386.   s4:="";
  387.   Number(Length(s4));
  388.   WriteLn;
  389.  
  390. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  391. (* OverWrite                                                            *)
  392. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  393.   BreakPoint(ADR("Testing OverWrite"));
  394.   Print("overwriting 'teststring' s12 with 'xyz' at pos 0");
  395.   s12:="teststring";
  396.   OverWrite(s12,"xyz",0);
  397.   Result(s12);
  398.   Print("overwriting 'teststring' s12 with 'xyz' at pos 4");
  399.   s12:="teststring";
  400.   OverWrite(s12,"xyz",4);
  401.   Result(s12);
  402.   Print("overwriting 'teststring' s12 with 'xyz' at pos 7");
  403.   s12:="teststring";
  404.   OverWrite(s12,"xyz",7);
  405.   Result(s12);
  406.   Print("overwriting 'teststring' s12 with 'xyz' at pos 9");
  407.   s12:="teststring";
  408.   OverWrite(s12,"xyz",9);
  409.   Result(s12);
  410.   Print("overwriting 'teststring' s12 with 'text' s4 at pos 4");
  411.   s12:="teststring";
  412.   s4:="text";
  413.   OverWrite(s12,s4,4);
  414.   Result(s12);
  415.   Print("overwriting 'testtext' s8 with 'string' at pos 4");
  416.   s8:="testtext";
  417.   OverWrite(s8,"string",4);
  418.   Result(s8);
  419.   WriteLn;
  420.  
  421. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  422. (* SubString                                                            *)
  423. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  424.   BreakPoint(ADR("Testing SubString"));
  425.   Print("slices ([0..10],3) of 'teststring' s12");
  426.   s12:="teststring";
  427.   WriteLn;
  428.   FOR n:=0 TO 10 DO
  429.     SubString(s12,s4,n,3);
  430.     Print(s4);
  431.     WriteLn;
  432.   END;
  433.   Print("slice (6,3) of 'testtext' s8");
  434.   s8:="testtext";
  435.   SubString(s8,s4,6,3);
  436.   Result(s4);
  437.   Print("slice (6,0) of 'testtext' s8");
  438.   SubString(s8,s4,6,0);
  439.   Result(s4);
  440.  
  441. END StringOpsTest.
  442.